<?php
declare(strict_types=1);

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Jobs;

use Qiniu\Auth;
use Hyperf\AsyncQueue\Job;
use Hyperf\DbConnection\Db;

class MineOrder extends Job
{


//    /**
//     * @Inject
//     * @var Sender
//     */
//    protected $sender;

//    use SerializationModel;
//    use Serialization;
    public $model;
    public $params;




    public $init = false;

    /**^M
     * ............................................................... $maxAttempts+1 ...^M
     *^M
     * @var int^M
     */
    protected $maxAttempts = 0;


    public function __construct($params)
    {
//        $this->model = $model;
        $this->params = $params;
        //1.订单修改
        //2.修改手机号信息
        //3.修改身份证信息
    }

    public function handle(): void
    {

        $type = data_get($this->params, 'type', '');
        $this->model = data_get($this->params, 'model', '');
        switch ($type) {
            case 1:
                $idNum = data_get($this->model, 'id_num', '');
                $mobile = data_get($this->model, 'mobile', '');
                $userId = data_get($this->model, 'user_id', '');
                $oid = data_get($this->model, 'id', '');
                $mineId = $userId;
                info('a', [$idNum, $mobile, $userId, $oid]);
                if (!empty($idNum)) {
                    info(1);
                    $ud = Db::table('user_detail')->where('id_num', '=', $idNum)->first();
                    if (!empty($ud)) {
                        info(2);
                        $mineId = data_get($ud, 'user_id', '');
                    } else {
                        info(3);
                        if (!empty($mobile)) {
                            info(4);
                            $u = Db::table('users')->where('mobile', '=', $mobile)->first();
                            if (!empty($u)) {
                                info(5);
                                $mineId = data_get($u, 'id', '');
                            }
                        }
                    }
                }
                info(6);


                Db::table('signups')->where('id', '=', $oid)
                    ->update([
                        'mine_id' => $mineId,
                    ]);
                break;
            case 2:
                $mobile = data_get($this->model, 'mobile', '');
                $uid = data_get($this->params, 'user_id', '');
                Db::table('signups')->where('mobile', '=', $mobile)->update([
                    'mine_id' => $uid,
                ]);

                break;
            case 3:
                $idNum = data_get($this->model, 'id_num', '');
                $uid = data_get($this->params, 'user_id', '');
                Db::table('signups')->where('id_num', '=', $idNum)->update([
                    'mine_id' => $uid,
                ]);
                break;
            default:
                return;
        }

    }
}
